<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- jsp中 第5种页面跳转方式 <meta http-equiv="refresh" content="300; url=index.jsp"> -->
<title>jsp相关面试题</title>
</head>
<body>

	jsp中5种页面跳转方式
	<%-- 1、<jsp:forward page="/index.jsp"></jsp:forward> ，浏览器地址不会改变 --%>

	<%-- 2、<%response.sendRedirect("/index.jsp");%>，浏览器地址改变 --%>

	<%-- 3、<% getServletContext().getRequestDispatcher("/index.jsp").forward(request, response); %> --%>
	<%-- 4、<% response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);response.setHeader("Location", "/index.jsp"); %> ，浏览器地址改变--%>

	<br> jsp 中设置cookie

	<%
		Cookie cookie = new Cookie("c", "ztq");
		cookie.setMaxAge(30 * 60);//过期时间30分钟
		response.addCookie(cookie);
	%>
	<br> jsp 中读取cookie<br>
	<%
		Cookie[] cookies = request.getCookies();
		Cookie cookie2 = null;
		
		if(cookies == null){
			out.println("沒有cookie");
		}else{
			for(int i =0; i < cookies.length; i++){
				cookie2 = cookies[i];
				out.println(cookie2.getName() + "-->" + cookie2.getValue() + "<br>");
			}
		}
	%>
	jsp 中定义方法<br>
	<%!
		public String jspMethod(){
		
		return "定义成功";
	}
	%>
	
	<% out.println(jspMethod()); %>
	jsp 9大內置對象<br>
<%-- 	<% request, response, session, application, out, page, pageContext, config, exception  %> 
Exception对象获取， Exception e = (Exception) request.getAttribute("exception");
--%>

jsp 动态include 静态include<br>
<!-- jsp:include是先编译一下included.jsp文件，然后再包含        先编译，后包含 -->
<!-- @ include是先把文件包含就来，然后统一编译                   先包含，后编译 -->
<jsp:include page="test.jsp" flush="true"></jsp:include><br>
<%@include file="test.jsp" %>

<script type="text/javascript">
	var x = 1, y = 0, z = 0;
	
	function add(n){
		n = n + 1;
	}
	
	y = add(x);
	
	function add(n){
		n = n + 3;
	}
	z = add(x);
	console.log(y);
	console.log(z);
</script>
</body>
</html>